//
//  UserNameViewController.m
//  享动
//
//  Created by darker on 16/4/11.
//  Copyright © 2016年 HHUI. All rights reserved.
//

#import "UserNameViewController.h"

@interface UserNameViewController () <UITextFieldDelegate>

@end

@implementation UserNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"修改昵称";
    
    self.view.backgroundColor = [UIColor whiteColor];
    _nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 64 + 5, KWIDTH - 20, 30)];
    _nameTextField.borderStyle = UITextBorderStyleBezel;
    _nameTextField.layer.cornerRadius = 10;
    _nameTextField.delegate = self;
    _nameTextField.text = _userName;
    // 出现清除按钮
    _nameTextField.clearButtonMode = UITextFieldViewModeAlways;
    [self.view addSubview:_nameTextField];
    
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(rightButtonAction)];
    self.navigationItem.rightBarButtonItem = rightButton;
    
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(leftButtonAction)];
    self.navigationItem.leftBarButtonItem = leftButton;
}

- (BOOL) textFieldShouldReturn:(UITextField *)textField
{
    [_nameTextField resignFirstResponder];
    return YES;
}

- (void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [_nameTextField resignFirstResponder];
}

// 完成
- (void) rightButtonAction
{
    if (_userName != nil)
    {
        _myUserName(_nameTextField.text);
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}

// 取消
- (void) leftButtonAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
